﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GC2.Bussines;
using GC2.Bussines.BMAdmin;
using GC2.Entities.Admin;
using GC2.Entities.Seguridad;
using GC2.ExceptionHandler;

public partial class Empleados_TareasGestion : GenericPage
{
    #region Propiedades
    Usuarios usuario = new Usuarios();
    private Tareas tarea = new Tareas();    
    private ExceptionConstructor exNew = new ExceptionConstructor();
    private int Accion;
    #endregion

    #region Controles
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            SetearCultura();
            SetearConexion();
            if (!this.IsPostBack)
            {
                usuario = (Usuarios)Session["UsuarioActual"];
                Accion = Convert.ToInt16(Session["Accion"].ToString());
                tarea = (Tareas)Session["Tarea"];

                if (Accion > 1)
                {
                    tarea = (Tareas)Session["Tarea"];
                    HidrataControles(tarea);
                    if (Accion == 2)
                    { 
                        lblAccion.Text = "Modificación: Tarea";
                    }
                    else
                    {
                        lblAccion.Text = "Viendo Datos";
                    }
                }
                if (Accion == 1)
                {
                        lblAccion.Text = "Nueva Tarea";
                }
            }
        }
        catch (Exception ex) { ErrorUI(ex); }

    }
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        try
        {
            DesHidrataControles();
        }
        catch (Exception ex) { ErrorUI(ex); }
    }

    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Seguridad/Default.aspx", false);
    }
    #endregion

    #region Métodos

    #region HidrataControles
    /// <summary>
    /// Hidrata Controles Tarea
    /// </summary>
    /// <param name="titular"></param>
    private void HidrataControles(Tareas tarea)
    {
        try
        {
            txtTarea.Text = tarea.Tarea;
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #region DesHidrataControles
    /// <summary>
    /// DesHidrata Controles Proveedor
    /// </summary>
    /// <param name="titular"></param>
    private void DesHidrataControles()
    {
        try
        {
            BMTareas bmTareas = new BMTareas(Connection);
            Accion = Convert.ToInt16(Session["Accion"].ToString());
            tarea = (Tareas)Session["Tarea"];
            tarea.Tarea = txtTarea.Text;
            if (Accion == 1)
            {
                tarea.Id_Tarea = bmTareas.BMTareasGetLast().Id_Tarea;
                tarea.Id_Tarea++;
                bmTareas.BMTareasInsert(tarea);
                lblAccion.Text = "Nueva Tarea Creada";
                btnGuardar.Enabled = false;
            }
            if (Accion == 2)
            {
                bmTareas.BMTareasUpdate(tarea);
                lblAccion.Text = "Tarea Actualizada";
            }
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #endregion

}
